<template>
  <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>品牌管理</el-breadcrumb-item>
        <el-breadcrumb-item>品牌回收站</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-table :data="brandlistBin" stripe border>
        <el-table-column label="品牌名称" prop="brandname"></el-table-column>
        <el-table-column prop="brandimg" label="品牌图标">
          <template slot-scope="scope">
            <el-image
            style="width: 50px; height: 50px"
            :src="`http://localhost:3000/${scope.row.brandimg}`"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="brandsort" label="品牌排序"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="warning" @click="restore(scope.row)" size="mini">还原</el-button>
            <el-button type="danger" @click="delBrand(scope.row._id)" size="mini">永久删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="query.page"
      :page-sizes="[2, 3, 4, 5]"
      :page-size="query.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="bintotal"
      background>
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import {mapState, mapActions} from 'vuex'
export default {
  data(){
    return{
      query:{
        page:1,
        pagesize: 2
      }
    }
  },
  created(){
    this.getRectycle()
  },
  methods:{
    ...mapActions('brandAbout',['getRecyclebin','restoreData','delBrandData']),
    getRectycle(){
      this.getRecyclebin(this.query)
    },
    handleSizeChange(newSize){
      this.query.pagesize = newSize
      this.query.page = 1
      this.getRectycle()
    },
    // 监听页码变化
    handleCurrentChange(newPage){
      this.query.page = newPage
      this.getRectycle()
    },
    // 还原
    restore(row){
      this.restoreData(row)
      this.getRectycle()
    },
    // 彻底删除
    delBrand(id){
      this.$confirm('此操作将永久删除该品牌, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.delBrandData(id)
        this.getRectycle()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });          
      });
    }
  },
  computed:{
    ...mapState('brandAbout',['bintotal','brandlistBin'])
  }
}
</script>

<style>

</style>